TO USE THESE PROGRAMS FIRST CUT THEM OUT TO SEPARATE FILES




      EXAMPLE PROLOG PROGRAMS

these examples are from:
	Logic Programming and Knowledge Engineering by Tore Amble

robotplan
goal|brother(abel,Q),PRINT(q=,Q)
parent(adam,cain)
parent(adam,abel)
ancestor(X,Y)|parent(X,Y)
ancestor(X,Z)|parent(Y,Z)ancestor(X,Y)
NOT(ancestor(X,X))
brother(X,Y)|father(F,X)father(F,Y),NOT(eq(X,Y))
father(adam,cain)
father(adam,abel)

alpine skier
goal|clubmember(X),climber(X),neg(skier(X)),PRINT(x=,X)
clubmember(tony)
clubmember(mike)
clubmember(john)
climber(X)|clubmember(X),neg(skier(X))
neg(like(X,rain))|climber(X)
neg(skier(X))|neg(likes(X,snow))
neg(likes(mike,X))|likes(tony,X)
likes(mike,X)|neg(likes(tony,X))
likes(tony,rain)
likes(tony,snow)

connected
leg(a,d)
leg(a,c)
leg(a,b)
leg(c,d)
leg(d,e)
connect(X,Y)|leg(X,Y)
connect(X,Z)|leg(X,Y),connect(Y,Z)
deriv(x,1)
deriv(N,0)|number(N)
deriv(+(U,V),+(U1,V1))|deriv(U,U1),deriv(V,V1)
deriv(-(U,V),-(U1,V1))|deriv(U,U1),deriv(V,V1)
deriv(*(U,V),+(*(U1,V),*(U,V1)))|deriv(U,U1),deriv(V,V1)
deriv(/(U,V),/(-(*(U1,V),*(U,V1)),*(V,V)))|deriv(U,U1),deriv(V,V1)
deriv(^(U,N),^(*(N,U),-(N,1)))|deriv(U,U1)
deriv(EXP(U),*(EXP(U),U1))|deriv(U,U1)

ex1

p(X)|q(X),r(X)
p(scrmph)
q(a)
q(b)
q(c)
r(b)
r(c)
s(b)
s(c)
w(U)|s(U)
goal|p(U),w(U)
goal|alter(ego)
goal|DQ(p(X,p(Z,Y)),Z,p(X,Y),Z),lst(X,Y,Z)
DQ(p(p(U,U),U),R(a,b),V,R(A,B))
lst(I,J,K)

orphan
father(hans,gerhard)
mother(lise,gerhard)
father(ivan,heinz)
parent(X,Y)|father(X,Y)
parent(X,Y)|mother(X,Y)
hasparent(Y)|parent(X,Y)
child(gerhard)
child(heinz)
child(beate)
status(gerhard,healthy)
status(heinz,sick)
orphan(X)|child(X),noparent(X)
noparent(X)|parent(Y,X),!,fail
noparent(X)

construct
cons(X,Y,.(X,Y))
q1|cons(a,b,Z),PRINT(z=,Z)
q2|cons(a,@,Z),PRINT(z=,Z)
MEM(X,.(X,Y))
MEM(X,.(U,V))|MEM(X,V)
g1|MEM(a,.(a,.(b,.(c,@))))
d1|delete(X,.(a,.(b,.(c,@,))),Y),PRINT(x=,X),PRINT(y=,Y)
delete(X,.(X,Y),Y)
delete(X,.(U,V),.(U,W))|delete(X,V,W)

NETWORK database
hasa(animal,inhalant)
hasa(animal,bloodtemp)
hasa(animal,food)
hasa(elephant,texture)
has(mammal,inhalant,oxygen)
has(mammal,bloodtemp,warm)
has(elephant,texture,wrinkled)
has(elephant,food,peanuts)
has(elephant,colour,grey)
has(shark,habitat,ocean)
has(shark,colour,grey)
has(X,Attribute,Value)|isa(X,C),has(C,Attribute,Value)
are(mammal,animal)
are(shark,animal)
are(spermwhale,mammal)
are(elephant,mammal)
isa(clyde,elephant)
isa(bonnie,shark)
isa(X,Z2)|are(Z1,Z2),isa(X,Z1)

orphan2
orphan(X)|NOT(parent(Y,X))
NOT(X)|X,!,fail
father(hans,gerhard)
mother(lise,gerhard)
father(ivan,heinz)
parent(X,Y)|father(X,Y)
parent(X,Y)|mother(X,Y)
hasparent(Y)|parent(X,Y)

quicksort
QS(.(X,Xs))|part(Xs,X,L,B),QS(L,Ls),QS(B,Bs),APPEND(Ls,.(X,Bs),Ys)
QS(@,@)
part(.(X,Xs),Y,.(X,Ls),Bs)|X<=Y,part(Xs,Y,Ls,Bs)
part(.(X,Xs),Y,Ls,.(x,Bs))|X>Y,part(Xs,Y,Ls,Bs)
partition(@,Y,@,@)
APPEND(@,List,List)
APPEND(.(First,Rest),List,.(First,Temp))|APPEND(Rest,List,Temp)

reverse
g1|QS(.(2,.(1,.(3,@))),Qs)
g1|reverse(.(a,.(b,.(c,.(d,.(e,.(f,@)))))),Q),PRINT(q=,Q)
g2|reverse(.(a,.(b,.(c,.(d,.(e,.(f,.(g,.(h,.(i,@))))))))),Q),PRINT(q=,Q)
reverse(@,@)
reverse(.(X,Y),Z)|reverse(Y,Y1),APPEND(Y1,.(X,@),Z)
APPEND(@,List,List)
APPEND(.(First,Rest),List,.(First,Temp))|APPEND(Rest,List,Temp)

expert SYSTEM
goal|solve((NOT(X,Y),BOX(X),BOX(Y))),PRINT(x=,X),PRINT(y=,Y)
solve(Y)|prove(Y,false,C)
prove((P,Q),U,W)|!,prove(P,U,V),prove(Q,V,W)
prove(NOT(eq(X,Y)),P,C)|==(X,Y),!,fail
prove(NOT(eq(X,Y)),P,P)|NOT(eq(X,Y)),!
prove(NOT(eq(X,Y)),P,OR(==(X,Y),P))|!
prove(X,U,U)|NOT((X,Any)),!,X,NOT(U)
prove(Y,U,V)|(Y,Z),prove(Z,U,V)

robotplan
BOX(a)
BOX(b)
BOX(c)
holds(ON(a,b),start)
holds(ON(b,floor),start)
holds(ON(c,floor),start)
holds(CLEAR(a),start)
holds(CLEAR(c),start)
holds(ON(a,b),final)
holds(ON(b,c),final)
holds(ON(c,floor),final)





